﻿//-----------------------------------------------------------------------
// <copyright file="Utils.cs" company="Numbrella foundation">
// Copyright (c) Numbrella foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Numbrella.Core
{
    using System.Globalization;
    using System.Security.Cryptography;
    using System.Text;

    /// <summary>
    /// Class with useful utilites.
    /// </summary>
    public static class Utils
    {
        /// <summary>
        /// Calculates MD5 hash code of given string.
        /// </summary>
        /// <param name="input">String for hash code calculation.</param>
        /// <returns>MD5 hash code of given string.</returns>
        public static string GetHashCode(string input)
        {
            MD5 hasher = MD5.Create();
            byte[] data = hasher.ComputeHash(Encoding.Default.GetBytes(input));

            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
                stringBuilder.Append(data[i].ToString("x2", CultureInfo.InvariantCulture));

            return stringBuilder.ToString();
        }
    }
}
